package org.example.struct.array;

import java.util.Arrays;

/**
 * @author liyishan
 * @date 2024/2/20 09:43
 * @apiNote
 */

public class LCR158InventoryManagement {

    public static void main(String[] args) {
        int[] stock ={1,2,1,3,1,4,1,5};
        System.out.println(inventoryManagement(stock));
    }

    public static  int inventoryManagement(int[] stock) {
        int count = 0;
        Integer candidate = null;
        for(int num:stock){
            if(count == 0){
                candidate = num;
            }
            count += (num == candidate) ? 1:-1;
        }
        return candidate;
    }

    public int inventoryManagement1(int[] stock) {
        Arrays.sort(stock);
        return stock[stock.length/2];
    }
}
